package cn.iocoder.yudao.module.book.service.user;

import cn.iocoder.yudao.module.book.controller.app.user.vo.UserSettingDefaultsRespVO;
import cn.iocoder.yudao.module.book.dal.dataobject.config.BookConfigDO;
import cn.iocoder.yudao.module.book.dal.mysql.config.BookConfigMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserSettingServiceImpl implements UserSettingService {

    @Resource
    private BookConfigMapper bookConfigMapper;

    @Override
    public UserSettingDefaultsRespVO getUserSettingDefaults() {
        UserSettingDefaultsRespVO respVO = new UserSettingDefaultsRespVO();
        respVO.setCsQrCode(getConfigValue("user.setting.cs_qr_code"));
        respVO.setWechatGroupQrCode(getConfigValue("user.setting.wechat_group_qr_code"));
        respVO.setEnlightenmentMethodsPage(getConfigValue("user.setting.enlightenment_methods_page"));
        return respVO;
    }

    private String getConfigValue(String configKey) {
        BookConfigDO config = bookConfigMapper.selectByConfigKey(configKey);
        return config != null ? config.getValue() : "";
    }
}